// See https://aka.ms/new-console-template for more information

using GenericsExercise;

int a = 10;
int b = 15;

Console.WriteLine("------------------------int swap value------------------------");
Console.WriteLine($"int Before Swap: a = {a}, b = {b}");
SwapValue.Swap(ref a, ref b);
Console.WriteLine($"int After Swap: a = {a}, b = {b}");

Console.WriteLine("------------------------string swap value------------------------");

string x = "Hello";
string y = "Generic!";
Console.WriteLine($"string Before Swap: x y=  {x} {y}");
SwapValue.Swap(ref x, ref y);
Console.WriteLine($"string After Swap: x y=  {x} {y}");


Console.WriteLine("------------------------List<int> swap value------------------------");
List<int> list1 = new List<int>() { 0,1,2,3};
List<int> list2 = new List<int>() { 4, 5, 6, 7 };
Console.WriteLine($"List<int> Before Swap: list1 = {string.Join(", ", list1)}, list2 = {string.Join(", ", list2)}");
SwapValue.Swap(ref list1 , ref list2);
Console.WriteLine($"List<int> After Swap: list1 = {string.Join(" ,",list1)}, list2 = {string.Join(" ,",list2)}");

Console.WriteLine("------------------------Array swap value------------------------");
int[] arr1 = new int[5] { 1, 2, 3, 4, 5 };
int[] arr2 = new int[5] { 6, 7, 8, 9, 10 };
Console.WriteLine($"Array Before Swap: arr1 = {string.Join(", ", arr1)}, arr2 = {string.Join(", ", arr2)}");
SwapValue.Swap(ref arr1, ref arr2);
Console.WriteLine($"Array After Swap: arr1 = {string.Join(" ,", arr1)}, arr2 = {string.Join(" ,", arr2)}");

Console.WriteLine("------------------------Person swap value------------------------");
Person person1 = new Person
{
    Name = "test1",
    Age = 18,
    Sex = "男"
};
Person person2 = new Person
{
    Name = "test2",
    Age = 19,
    Sex = "女"
};

Console.WriteLine($"Person Before Swap: person1 = {person1.ToString()}, person2 = {person2.ToString()}");
SwapValue.Swap(ref person1, ref person2);
Console.WriteLine($"Person After Swap: person1 = {person1.ToString()}, person2 = {person2.ToString()}");




Console.WriteLine();
Console.WriteLine();
Console.WriteLine("----------------------------------------------Base Repository Verify --------------------------------------------");
User user = new User()
{
    Id = 1,
    Name = "Test1"
};

User user1 = new User()
{
    Id = 2,
    Name = "Test2"
};

User user2 = new User()
{
    Id = 3,
    Name = "Test3"
};

User user3 = new User()
{
    Id = 4,
    Name = "Test4"
};

User user4 = new User()
{
    Id = 5,
    Name = "Test5"
};

//BaseRepository<User> userRepository = new BaseRepository<User>();
//userRepository.Add(user);
//userRepository.Add(user1);
//userRepository.Add(user2);
//userRepository.Add(user3);
//userRepository.Add(user4);
//var userList = userRepository.GetAll();
//userList.ForEach(user =>
//{
//    Console.WriteLine(user.ToString());
//});



Console.WriteLine("-------------------------------------模拟并发问题-----------------------------------------");
BaseRepository<User> baseRepository = new BaseRepository<User>();
Thread thread = new Thread(baseRepository.AddUser);

Thread thread1 = new Thread(baseRepository.AddUser);

Thread thread2 = new Thread(baseRepository.AddUser);

Thread thread3 = new Thread(baseRepository.AddUser);

Thread thread4 = new Thread(baseRepository.AddUser);
thread.Start(user);
thread1.Start(user1);
thread2.Start(user2);
thread3.Start(user3);
thread4.Start(user4);
thread.Join();
thread1.Join();
thread2.Join();
thread3.Join();
thread4.Join();

var userList = baseRepository.GetAll();
userList.ForEach(user =>
{
    Console.WriteLine(user.ToString());
});

